<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <link rel="stylesheet" type="text/css" href="js/layui/css/layui.css"/>
  <script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
  <script src="js/layui/layui.js" type="text/javascript" charset="utf-8"></script>
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
 
<table class="layui-hide" id="test" lay-filter="test"></table>
 
<!-- <script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
    <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
    <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
  </div>
</script> -->
 
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="update">修改</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
              
          


 
<script>
layui.use('table', function(){
  var table = layui.table;
  
  table.render({
    elem: '#test'
    ,url:'http://127.0.0.1:8080//teResult/teache'
    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
    ,defaultToolbar: [ 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
      title: '提示'
      ,layEvent: 'LAYTABLE_TIPS'
      ,icon: 'layui-icon-tips'
    }]
    ,title: '用户数据表'
    ,cols: [[
     
      {field:'tcciid', title:'ID', width:80, fixed: 'left', unresize: true, sort: true,hide:true}
      ,{field:'teacherid', title:'教师id', width:220,hide:true}
        ,{field:'teachername', title:'教师姓名', width:220}
     
      
      ,{field:'courseid', title:'课程名称', width:220,edit: 'text',hide:true}
	  ,{field:'coursename', title:'课程名称', width:220}
	  ,{field:'studentid', title:'班级名称', width:120,hide:true}
	  ,{field:'studentname', title:'评教人', width:220}
       ,{field:'score', title:'分数', width:120,edit: 'text'}
	   ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
	  
    ]]
	
    ,page: {
	 		 layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
	 		         //,curr: 5 //设定初始在第 5 页
	 		         ,limit:10 //一页显示多少条
	 		         ,limits:[5,10,15]//每页条数的选择项
	 		         ,groups: 2 //只显示 2 个连续页码
	 		         ,first: "首页" //不显示首页
	 		         ,last: "尾页" //不显示尾页
	 	 }
  });
  
  //头工具栏事件
  table.on('toolbar(test)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'getCheckData':
        var data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      break;
      case 'getCheckLength':
        var data = checkStatus.data;
        layer.msg('选中了：'+ data.length + ' 个');
      break;
      case 'isAll':
        layer.msg(checkStatus.isAll ? '全选': '未全选');
      break;
      
      //自定义头工具栏右侧图标 - 提示
      case 'LAYTABLE_TIPS':
        layer.alert('这是工具栏右侧自定义的一个图标按钮');
      break;
    };
  });
  
  //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
    //console.log(obj)
    if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
        obj.del();
         layer.close(index);
		var tccid=obj.data.tcciid;
		$.ajax({
			type:"get",
			 url:"http://127.0.0.1:8080//teResult/teacheDel",
			 
			contentType:"application/x-www-form-urlencoded;charset=utf-8",
			data: {'tcciid':tccid},
			success:function(msg){
				 layer.msg(msg.data, {time:1000, icon:6, shift:6}, function(){});
				
			},
			error:function(msg){
				layer.msg(msg.reason, {time:1000, icon:6, shift:6}, function(){});
			}
			
		})
      });
    } else if(obj.event === 'update'){
		  var tcciid=obj.data.tcciid;
		  var score=obj.data.score;
		  $.ajax({
			  type:"get",
			   url:"http://127.0.0.1:8080//teResult/teacheUpdate",
			   
			  contentType:"application/x-www-form-urlencoded;charset=utf-8",
			  data: {'tcciid':tcciid,'score':score},
			  success:function(msg){
			  	 layer.msg(msg.data, {time:1000, icon:6, shift:6}, function(){});
			  	
			  },
			  error:function(msg){
			  	layer.msg(msg.reason, {time:1000, icon:6, shift:6}, function(){});
			  }
		  })
    }
  });
});
</script>

<script>
	$("#line2").click(function(){
		layer.open({
		  type: 2,
		  area: ['700px', '450px'],
		  fixed: false, //不固定
		  maxmin: true,
		  content: 'sysAddTeacher_clazz_Courser.html'
		});
	})
	
</script>
</body>
</html>